package internal.standard;

import java.util.Iterator;

import org.lightmtv.LightMtvException;
import org.lightmtv.config.MtvFilter;
import org.lightmtv.config.MtvFilterChain;
import org.lightmtv.request.Request;
import org.lightmtv.response.Response;

public class StandardFilterChain implements MtvFilterChain {
	
	private Iterator<MtvFilter> iterator;
	
	public StandardFilterChain(Iterator<MtvFilter> iterator) {
		super();
		this.iterator = iterator;
	}

	public Response doFilter(Request request) {
		if(iterator.hasNext()){
			MtvFilter current = iterator.next();
			return current.doFilter(request, this);
		}
		throw new LightMtvException("MtvFilter has go to the end.");
	}
}
